<?php

class Members extends La_Controller {
	function __construct() {
		parent::__construct();
		$this->load->model(array("User_model", "Vertification_model", "Banned_model"));
		if (!$this->authorize->is_admin_logged_in()) {
			la_redirect("/admin/login", "请先登录");
		}
		$this->data['nav'] = 'member';
	}
	
	function index() {
		echo "It works";
	}	
	/**
	 * 用户信息验证（后台那个PPT的9、10、11三页）
	 */
	public function user_verify() {
		$type = $this->input->get("type");
		if (empty($type)) {
			$type = "id";
		}
		$this->data['type'] = $type;
		switch ($type) {
			case "pass":
				$condition = " and v.status=1 ";
				break;
			case "expert":
				$condition = " and v.status=0 and v.type=2 ";
				break;
			case "id":
			default:
				$condition = " and v.status=0 and v.type=1 ";
				break;
		}
		$vertifications = $this->Vertification_model->find_by_condition($condition);
		$this->data['vertifications'] = $vertifications;
		$this->load->view('admin/user_verify', $this->data);
	}
	
	public function approve() {
		$act = $this->input->post("act");
		$ids = $this->input->post("ids");
		$type = $this->input->post("type");
		if ($act == 'pass') {
			foreach($ids as $id) {
				$this->Vertification_model->update(array('status' => 1, 'modified' => date("Y-m-d H:i:s")), $id);
			}
		} else {
			foreach($ids as $id) {
				$this->Vertification_model->update(array('status' => -1, 'modified' => date("Y-m-d H:i:s")), $id);
			}
		}
		la_redirect("/console/members/user_verify?type=" . $type, "操作成功");
	}
	/**
	 * 管理用户
	 */
	public function banned() {
		$this->load->model("Feedback_model");
		$this->data['feedbacks'] = $this->Feedback_model->find_all_story();
		$this->load->view('admin/member_admin', $this->data);
	}
	
	public function save_banned() {
		$data['user_id'] = $this->input->post("user_id");
		$data['type'] = $this->input->post("type");
//		if ($data['type'] != -1) {
//			$data['created'] = date("Y-m-d H:i:s");
//			$this->Banned_model->add($data);
//		} else {
//			$this->User_model->set_user_noactive($data['user_id']);
//		}
		if(!is_array($data['user_id'])) {
			$this->User_model->update_user_status($data['user_id'], $data['type']);
		} else {
			foreach($data['user_id'] as $uid) {
				$this->User_model->update_user_status($uid, $data['type']);
			}
		}
		la_redirect("/console/members/banned", "操作成功");
	}
	
}